import React, { Component} from 'react'
import { Redirect} from 'react-router-dom'
import { connect} from 'react-redux'
import {
    NavBar, InputItem,
    List, Button, WhiteSpace, TextareaItem, Toast
} from 'antd-mobile'


import { updateManito} from '../../redux/actions'
import HeaderSelect from '../../components/headerSelect/headerSelect'


class DaShen extends Component{

    state = {
        header: '',//头像
        post: '',//职位
        info: '',//个人或者职位的描述
    }

    maniClick = (type, val) => {
        this.setState({
            [type]: val
        })
    }

    setBoxxHeader = header => {
        this.setState({
            header
        })
    }

    //这里发送请求
    saveClick = () => {
        //这里一旦保存之后就会发送ajax请求
        this.props.updateManito(this.state, this.remin)
    }

    //提示错误的信息
    remin = (msg) => {
        Toast.fail(msg, 1)
    }

    render(){
        const { info} = this.props.user
        if ( info){
            console.log('优质')
            return <Redirect to='/manitolist' />
        }
        return(
            <div>
                <NavBar>大神信息完善</NavBar>
                <HeaderSelect setBoxxHeader={ this.setBoxxHeader} />
                <List>
                    <WhiteSpace size='lg' />
                    <InputItem placeholder='输入您的求职岗位' onChange={ val => { this.maniClick('post', val)}}>求职岗位</InputItem>
                    <TextareaItem
                        title='个人介绍'
                        rows={3}
                        onChange={ val => { this.maniClick('info', val)}}
                    />
                    <Button type='primary' onClick={ this.saveClick}>保存</Button>
                </List>
            </div>
        )
    }
}

export default connect(
    state => ({ user: state.user}),
    { updateManito}
)(DaShen)
